{extend name="Base" /}
{block name="title"}{$title}{/block}
{block name="body"}
{load href="/js/clipboard.min.js"}
<legend>{$u.username}</legend>
<div class="am-tabs" data-am-tabs="{noSwipe: 1}">
	<ul class="am-tabs-nav am-nav am-nav-tabs">
		<li class="am-active"><a href="#tab1">基本信息</a></li>
		<li><a href="#tab2">安全&API</a></li>
		<li><a href="#tab3">客户端</a></li>
		<li><a href="#tab4">小货车</a></li>
	</ul>
	<div class="am-tabs-bd am-tabs-bd-ofv">
		<div class="am-tab-panel am-fade am-in am-active" id="tab1">
			<table class="am-table am-table-striped am-table-hover">
				<tbody>
				<tr>
					<td class="am-text-middle am-text-nowrap">身份ID</td>
					<td class="am-text-middle am-text-nowrap">
						<span class="am-badge am-radius am-badge-primary">{$u.uuid}</span>
					</td>
				</tr>
				<tr>
					<td class="am-text-middle am-text-nowrap">邀请码</td>
					<td class="am-text-middle am-text-nowrap"><a href="/index/users/sendinvite">永久邀请 {$u.longinv} / 临时邀请 {$u.shortinv}</a></td>
				</tr>
				<tr>
					<td class="am-text-middle am-text-nowrap">邀请人</td>
					<td class="am-text-middle am-text-nowrap">{$u.inviteby|getUserNameFromUID}</td>
				</tr>
				<tr>
					<td class="am-text-middle am-text-nowrap">注册邮箱</td>
					<td class="am-text-middle am-text-nowrap">{$u.email}</td>
				</tr>
				<tr>
					<td class="am-text-middle am-text-nowrap">注册时间</td>
					<td class="am-text-middle am-text-nowrap">{$u.addtime}</td>
				</tr>
				<tr>
					<td class="am-text-middle am-text-nowrap">当前IP</td>
					<td class="am-text-middle am-text-nowrap">{$u.ip}</td>
				</tr>
				<tr>
					<td class="am-text-middle am-text-nowrap">等级</td>
					<td class="am-text-middle am-text-nowrap">Lv.{$u.class}</td>
				</tr>
				<tr>
					<td class="am-text-middle am-text-nowrap">积分</td>
					<td class="am-text-middle am-text-nowrap">{$u.price}</td>
				</tr>
				<tr>
					<td class="am-text-middle am-text-nowrap">H&R</td>
					<td class="am-text-middle am-text-nowrap">{$u.hr}</td>
				</tr>
				<tr>
					<td class="am-text-middle am-text-nowrap">上传量</td>
					<td class="am-text-middle am-text-nowrap">{$u.uploaded|getSize}</td>
				</tr>
				<tr>
					<td class="am-text-middle am-text-nowrap">下载量</td>
					<td class="am-text-middle am-text-nowrap">{$u.downloaded|getSize}</td>
				</tr>
				<tr>
					<td class="am-text-middle am-text-nowrap">总上传时间</td>
					<td class="am-text-middle am-text-nowrap">{$u.seedtime|mkPrettyTime=###,1}</td>
				</tr>
				<tr>
					<td class="am-text-middle am-text-nowrap">总下载时间</td>
					<td class="am-text-middle am-text-nowrap">{$u.leechtime|mkPrettyTime=###,1}</td>
				</tr>
				</tbody>
			</table>
		</div>
		<div class="am-tab-panel am-fade" id="tab2">
			<table class="am-table am-table-striped am-table-hover">
				<tbody>
				<tr>
					<td class="am-text-middle am-text-nowrap">APP ID</td>
					<td class="am-text-middle am-text-nowrap">
						<span class="am-badge am-radius am-badge-primary">{$u.appid}</span>
					</td>
				</tr>
				<tr>
					<td class="am-text-middle am-text-nowrap">APP KEY</td>
					<td class="am-text-middle am-text-nowrap">
						<span class="am-badge am-radius am-badge-primary">{$u.appkey}</span>
					</td>
				</tr>
				<tr>
					<td class="am-text-middle am-text-nowrap">查看码</td>
					<td class="am-text-middle am-text-nowrap">
						<span class="am-badge am-radius am-badge-primary">{$u.extract}</span>
						<button type="button" class="am-btn am-btn-xs am-btn-secondary copy" data-clipboard-text="{$u.url}"
								data-am-popover="{theme: 'warning sm', content: '复制个人查看链接到剪贴板，必要时可重置', trigger: 'hover focus'}">复制
						</button>
					</td>
				</tr>
				<tr>
					<td class="am-text-middle am-text-nowrap">2FA状态</td>
					<td class="am-text-middle am-text-nowrap" id="twofastatus">{$u.2fa == 1 ? "已绑定" : "未绑定"}</td>
				</tr>
				<tr>
					<td class="am-text-middle am-text-nowrap">2FA软件下载</td>
					<td class="am-text-middle am-text-nowrap">
						<div><a href="https://itunes.apple.com/cn/app/google-authenticator/id388497605" target="_blank" title="iOS">iOS版本下载</a></div>
						<div><a href="https://play.google.com/store/apps/details?id=com.google.android.apps.authenticator2" target="_blank" title="Android">Android版本下载</a></div>
					</td>
				</tr>
				<tr>
					<td class="am-text-middle am-text-nowrap">2FA二维码</td>
					<td class="am-text-middle am-text-nowrap"><img src="{$u.qr}"/></td>
				</tr>
				<tr>
					<td class="am-text-middle am-text-nowrap">2FA验证码</td>
					<td class="am-text-middle am-text-nowrap">
						<div class="am-input-group">
							<input type="text" class="am-form-field" name="twofacode" placeholder="请输入身份验证软件显示的6位动态验证码">
							<span class="am-input-group-btn">
								<button class="am-btn am-btn-default" type="button" onclick="twofasubmit()">验证</button>
							</span>
						</div>
					</td>
				</tr>
				</tbody>
			</table>
		</div>
		<div class="am-tab-panel am-fade" id="tab3">
			我就这样告别山下的家，我实在不愿轻易让眼泪留下。我以为我并不差不会害怕，我就这样自己照顾自己长大。我不想因为现实把头低下，我以为我并不差能学会虚假。怎样才能够看穿面具里的谎话？别让我的真心散的像沙。如果有一天我变得更复杂，还能不能唱出歌声里的那幅画？
		</div>
		<div class="am-tab-panel am-fade" id="tab4">
			<table class="am-table am-table-striped am-table-hover">
				<tbody>
				<tr>
					<td class="am-text-middle am-text-nowrap" title="有效期">TTL</td>
					<td class="am-text-middle am-text-nowrap">
						<div class="am-input-group">
							<input type="text" class="am-form-field" name="ttl" placeholder="单位：分钟；默认永久有效">
							<span class="am-input-group-btn">
								<button class="am-btn am-btn-default" type="button" onclick="createRSS()">生成</button>
							</span>
						</div>
					</td>
				</tr>
				<tr>
					<td class="am-text-middle am-text-nowrap">RSS</td>
					<td class="am-text-middle am-text-nowrap">
						<button type="button" class="am-btn am-btn-secondary copyRSS" data-am-popover="{theme: 'warning', content: '复制专属RSS链接', trigger: 'hover focus'}">
							复制RSS链接
						</button>
					</td>
				</tr>
				</tbody>
			</table>
		</div>
	</div>
</div>
<br/>
<button type="button" class="am-btn am-btn-primary am-center" data-am-modal="{target: '#my-actions'}">操作</button>
<div class="am-modal-actions" id="my-actions">
	<div class="am-modal-actions-group">
		<ul class="am-list">
			<li class="am-modal-actions-header">选择你需要的操作</li>
			<li><a href="javascript:void(0)" onclick="reset(0)">重置身份ID</a></li>
			<li><a href="javascript:void(0)" onclick="reset(1)">重置APP相关</a></li>
			<li><a href="javascript:void(0)" onclick="reset(2)">重置个人查看码</a></li>
			<li><a href="javascript:void(0)" onclick="reset(3)">重置登录密码</a></li>
		</ul>
	</div>
	<div class="am-modal-actions-group">
		<button class="am-btn am-btn-secondary am-btn-block" data-am-modal-close>取消</button>
	</div>
</div>

<input type="hidden" name="uid" value="{$u.uid}"/>
<input type="hidden" name="jam" value="{$u.jam}"/>

{:token()}

<div class="am-modal am-modal-confirm" tabindex="-1" id="my-confirm">
	<div class="am-modal-dialog">
		<div class="am-modal-bd">
			<span id="content">确定要重置吗？</span>
			<input type="password" name="password" class="am-modal-prompt-input password" placeholder="请输入密码"/>
			<input type="hidden" name="password1" class="am-modal-prompt-input reset-password" placeholder="请输入想使用的密码"/>
			<input type="hidden" name="password2" class="am-modal-prompt-input reset-password" placeholder="请再次输入想使用的密码" onblur="check2pwd()"/>
			{php}$u['2fa'] == 0 ? : print('<input type="text" name="twofa" id="twofa" class="am-modal-prompt-input" placeholder="请输入2FA验证码"/>'){/php}
		</div>
		<div class="am-modal-footer">
			<span class="am-modal-btn" data-am-modal-cancel>取消</span>
			<span class="am-modal-btn" data-am-modal-confirm>确定</span>
		</div>
	</div>
</div>
<div class="am-modal am-modal-alert" tabindex="-1" id="my-alert">
	<div class="am-modal-dialog">
		<div class="am-modal-bd">重置失败</div>
		<div class="am-modal-footer">
			<span class="am-modal-btn" data-am-modal-confirm>知道了</span>
		</div>
	</div>
</div>

<script>
	function createRSS() {
		var ttl = $("input[name=ttl]").val();
		var $myalert = $("#my-alert");
		$.ajax({
			type: "POST",
			url: "/index/Rss/createCustomRSS",
			cache: false,
			data: {
				ttl: ttl
			},
			dataType: "json",
			success: function (data) {
				if (data.status === 1) {
					$myalert.find(".am-modal-bd").html(data.message);
					$myalert.modal();
					$(".copyRSS").attr("data-clipboard-text", data.data.url);
				} else {
					$myalert.find(".am-modal-bd").html(data.message);
					$myalert.modal();
					$("input[name=ttl]").val("");
					$(".copyRSS").attr("data-clipboard-text", "");
				}
			}
		});
	}

	new Clipboard(".copyRSS", function (e) {
		e.clearSelection();
	});

	new Clipboard(".copy", function (e) {
		e.clearSelection();
	});

	function twofasubmit() {
		var $myalert = $("#my-alert");
		$.ajax({
			type: "POST",
			url: "/index/Users/verify2FA",
			cache: false,
			data: {
				code: $("input[name=twofacode]").val(),
				k: $("input[name=jam]").val()
			},
			dataType: "json",
			success: function (data) {
				if (data.status === 1) {
					$myalert.find(".am-modal-bd").html(data.message);
					$myalert.modal();
					$("input[name=twofacode]").val("");
					$("#twofastatus").html(data.data.twofa);
				} else {
					$myalert.find(".am-modal-bd").html(data.message);
					$myalert.modal();
					$("input[name=twofacode]").val("");
				}
			}
		});
	}

	function check2pwd() {
		var $myalert = $("#my-alert");
		var pwd1 = $("input[name=password1]");
		var pwd2 = $("input[name=password2]");
		if (pwd1.val() !== pwd2.val()) {
			pwd1.val("");
			pwd2.val("");
			$("#my-confirm").modal("close");
			$myalert.find(".am-modal-bd").html("两次密码不一致");
			$myalert.modal();
		}
	}

	function reset(action) {
		$("input[name=password]").val("");
		var txt = "";
		var check = 0;
		if (action === 0) {
			txt = "确定重置身份ID吗？";
		} else if (action === 1) {
			txt = "确定重置APP相关吗？";
		} else if (action === 2) {
			txt = "确定重置个人查看码吗？";
		} else if (action === 3) {
			txt = "确定重置登录密码吗？";
			$(".password").attr("placeholder", "请输入当前使用的密码");
			$(".reset-password").attr("type", "password");
			check = 1;
		}
		$("#content").html(txt);
		$("#my-actions").modal({
			closeOnCancel: true
		});
		$("#my-confirm").modal({
			relatedTarget: this,
			onConfirm: function () {
				var data = {
					uid: $("input[name=uid]").val(),
					password: $("input[name=password]").val(),
					type: action,
					token: $("input[name=__token__]").val(),
					twofa: $("input[name=twofa]").val()
				};
				if (check === 1) {
					var reset = {
						password1: $("input[name=password1]").val(),
						password2: $("input[name=password2]").val()
					};
					data = Object.assign(data, reset);
				}
				var $myalert = $("#my-alert");
				var url = "/users";
				$.ajax({
					type: "POST",
					url: "/index/Users/verifyPassword",
					cache: false,
					data: data,
					dataType: "json",
					success: function (data) {
						if (data.status === 1) {
							$myalert.find(".am-modal-bd").html("重置成功");
							$myalert.modal({
								onConfirm: function () {
									location.href = url;
								}
							});
						} else if (data.status === 2) {
							$myalert.find(".am-modal-bd").html(data.message);
							$myalert.modal({
								onConfirm: function () {
									location.href = url;
								}
							});
						} else {
							$myalert.find(".am-modal-bd").html(data.message);
							$myalert.modal({
								onConfirm: function () {
									location.href = url;
								}
							});
						}
					}
				});
			},
			onCancel: function () {
				return false;
			}
		});
	}
</script>
{/block}